#include <REGX52.H>
#include "Delay.h"
#include "KeyPro.h"
#include "NixiePro.h"
#include "Timer1.h"
#include "IR.h"

sbit Motor=P1^0;

unsigned char Counter;//计数值
unsigned char Compare;//比较值
unsigned char Command,Speed;
void main()
{
	Timer1_Init();
	IR_Init();
	Compare = 50;
	while(1)
	{
		if(IR_GetDataFlag())
		{
			Command=IR_GetCommand();
			if(Command==IR_0){Speed=0;}
			if(Command==IR_1){Speed=1;}
			if(Command==IR_2){Speed=2;}
			if(Command==IR_3){Speed=3;}
			switch(Speed)
			{
				case 0: Compare=0;break;
				case 1: Compare=25;break;
				case 2: Compare=50;break;
				case 3: Compare=90;break;				
			}
		}
		Nixie(1,Speed);
	}
}

void Timer1_Routine() interrupt 3
{
	//100us
	static unsigned int T1Count;
	TL1 = 0xA4;				//设置定时初始值
	TH1 = 0xFF;				//设置定时初始值
	//1、数码管  按键检测
	T1Count++;
	if(T1Count>=20) 
	{
		T1Count = 0;
		Nixie_Loop();  
		Key_Loop();
	}
	//2、比较器检测
	Counter++;
	Counter%=100; // = if(Counter==100){Counter=0;}
	if(Counter<=Compare)
	{
		Motor = 1;//1:工作
	}
	else
	{
		Motor = 0;//0；停止
	}
}